< previous page page_174 next page >

Page 174
Brightness
Adjusting a pixel's brightness is only a little harder than calculating its complement. Suppose your goal is to change a picture's brightness by a percentage value where the value 0 is defined to mean no change, 100 means to increase all colors to the brightest possible value (white), and 100 means to decrease the colors to the darkest possible value (black).
To increase a color's brightness by a certain percentage, the program can add to each pixel's components the percentage times the difference between each component and its largest possible value 255. For example, a program could use the following equations to increase a pixel's components by a 75 percent:
e10a6a0a59f035e870d90cca05b85fce.gif
red = red + 0.75 * (255  red)
green = green + 0.75 * (255  green)
blue = blue + 0.75 * (255  blue)
To decrease a color's brightness by a certain percentage, a program can subtract from each pixel's components the percentage times the component's value. For example, a program could use the following equations to decrease a pixel's components by 75 percent:
e10a6a0a59f035e870d90cca05b85fce.gif
red = red  0.75 * red = (1  0.75) * red 
green = green  0.75 * green = (1  0.75) * green 
blue = blue  0.75 * blue = (1  0.75) * blue
Example program Bright, shown in Figure 6.3, uses these equations to adjust an image's brightness.
The only significant differences between this program and programs MakeGray and Complem are in the following statements that set a new pixel's color component values.
0174-01.jpg
Figure 6.3
Program Bright adjusts an image's brightness.

 
< previous page page_174 next page >